package com.xixi.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class UploadConfig implements WebMvcConfigurer {

    @Value("${file.upload-dir:src/main/resources/uploads}")
    private String uploadDir;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String projectRoot = System.getProperty("user.dir");
        String fullUploadPath = "file:" + projectRoot + "/" + uploadDir + "/trading/";

        registry.addResourceHandler("/uploads/trading/**")
                .addResourceLocations(fullUploadPath);
    }
}